from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-03-24 14:13:33.341593
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Wed, 24, Mar, 2021
Time: 14:13:37
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.0843
Nobs: 240.000 HQIC: -47.8636
Log likelihood: 2831.84 FPE: 9.65779e-22
AIC: -48.3895 Det(Omega_mle): 6.68835e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.446463 0.129936 3.436 0.001
L1.Burgenland 0.072879 0.064160 1.136 0.256
L1.Kärnten -0.214664 0.055550 -3.864 0.000
L1.Niederösterreich 0.088352 0.143651 0.615 0.539
L1.Oberösterreich 0.209850 0.133537 1.571 0.116
L1.Salzburg 0.263271 0.071874 3.663 0.000
L1.Steiermark 0.153105 0.094843 1.614 0.106
L1.Tirol 0.112998 0.063108 1.791 0.073
L1.Vorarlberg -0.033879 0.058728 -0.577 0.564
L1.Wien -0.084740 0.119835 -0.707 0.479
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.477537 0.154958 3.082 0.002
L1.Burgenland 0.007656 0.076516 0.100 0.920
L1.Kärnten 0.339473 0.066247 5.124 0.000
L1.Niederösterreich 0.115905 0.171314 0.677 0.499
L1.Oberösterreich -0.087084 0.159252 -0.547 0.584
L1.Salzburg 0.209019 0.085715 2.439 0.015
L1.Steiermark 0.131708 0.113107 1.164 0.244
L1.Tirol 0.136268 0.075261 1.811 0.070
L1.Vorarlberg 0.159599 0.070037 2.279 0.023
L1.Wien -0.476846 0.142912 -3.337 0.001
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.307091 0.062292 4.930 0.000
L1.Burgenland 0.094015 0.030759 3.057 0.002
L1.Kärnten -0.022003 0.026631 -0.826 0.409
L1.Niederösterreich 0.032857 0.068867 0.477 0.633
L1.Oberösterreich 0.302724 0.064018 4.729 0.000
L1.Salzburg 0.012964 0.034457 0.376 0.707
L1.Steiermark 0.011548 0.045468 0.254 0.800
L1.Tirol 0.071820 0.030254 2.374 0.018
L1.Vorarlberg 0.091015 0.028154 3.233 0.001
L1.Wien 0.104708 0.057449 1.823 0.068
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.210573 0.064863 3.246 0.001
L1.Burgenland 0.020654 0.032028 0.645 0.519
L1.Kärnten 0.008941 0.027730 0.322 0.747
L1.Niederösterreich 0.048526 0.071710 0.677 0.499
L1.Oberösterreich 0.397858 0.066661 5.968 0.000
L1.Salzburg 0.082175 0.035879 2.290 0.022
L1.Steiermark 0.142055 0.047345 3.000 0.003
L1.Tirol 0.047338 0.031503 1.503 0.133
L1.Vorarlberg 0.080569 0.029317 2.748 0.006
L1.Wien -0.038633 0.059821 -0.646 0.518
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.517791 0.126766 4.085 0.000
L1.Burgenland 0.080500 0.062595 1.286 0.198
L1.Kärnten 0.006809 0.054195 0.126 0.900
L1.Niederösterreich -0.040819 0.140146 -0.291 0.771
L1.Oberösterreich 0.141381 0.130278 1.085 0.278
L1.Salzburg 0.050484 0.070120 0.720 0.472
L1.Steiermark 0.092309 0.092529 0.998 0.318
L1.Tirol 0.214734 0.061568 3.488 0.000
L1.Vorarlberg 0.037460 0.057295 0.654 0.513
L1.Wien -0.090334 0.116911 -0.773 0.440
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.199686 0.095479 2.091 0.036
L1.Burgenland -0.020265 0.047146 -0.430 0.667
L1.Kärnten -0.025940 0.040819 -0.635 0.525
L1.Niederösterreich -0.047413 0.105557 -0.449 0.653
L1.Oberösterreich 0.440788 0.098125 4.492 0.000
L1.Salzburg 0.003071 0.052814 0.058 0.954
L1.Steiermark -0.012455 0.069692 -0.179 0.858
L1.Tirol 0.164759 0.046373 3.553 0.000
L1.Vorarlberg 0.065182 0.043154 1.510 0.131
L1.Wien 0.239569 0.088057 2.721 0.007
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.245346 0.122699 2.000 0.046
L1.Burgenland 0.019063 0.060587 0.315 0.753
L1.Kärnten -0.061673 0.052456 -1.176 0.240
L1.Niederösterreich -0.054628 0.135650 -0.403 0.687
L1.Oberösterreich 0.008405 0.126099 0.067 0.947
L1.Salzburg 0.077089 0.067871 1.136 0.256
L1.Steiermark 0.345326 0.089560 3.856 0.000
L1.Tirol 0.455485 0.059593 7.643 0.000
L1.Vorarlberg 0.145488 0.055457 2.623 0.009
L1.Wien -0.174945 0.113160 -1.546 0.122
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.123188 0.143336 0.859 0.390
L1.Burgenland 0.047718 0.070777 0.674 0.500
L1.Kärnten -0.063985 0.061279 -1.044 0.296
L1.Niederösterreich 0.209824 0.158465 1.324 0.185
L1.Oberösterreich -0.027346 0.147308 -0.186 0.853
L1.Salzburg 0.212871 0.079286 2.685 0.007
L1.Steiermark 0.134835 0.104624 1.289 0.197
L1.Tirol 0.050441 0.069616 0.725 0.469
L1.Vorarlberg 0.085938 0.064784 1.327 0.185
L1.Wien 0.228302 0.132193 1.727 0.084
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.588743 0.078593 7.491 0.000
L1.Burgenland -0.042153 0.038808 -1.086 0.277
L1.Kärnten -0.027834 0.033600 -0.828 0.407
L1.Niederösterreich 0.010154 0.086888 0.117 0.907
L1.Oberösterreich 0.333998 0.080770 4.135 0.000
L1.Salzburg 0.018476 0.043473 0.425 0.671
L1.Steiermark -0.034124 0.057366 -0.595 0.552
L1.Tirol 0.088266 0.038171 2.312 0.021
L1.Vorarlberg 0.112598 0.035522 3.170 0.002
L1.Wien -0.039602 0.072483 -0.546 0.585
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.136126 0.033972 0.158238 0.215667 0.053402 0.075323 -0.002346 0.153621
Kärnten 0.136126 1.000000 0.009733 0.204371 0.174961 -0.078889 0.158289 0.029424 0.305569
Niederösterreich 0.033972 0.009733 1.000000 0.254380 0.056712 0.266859 0.144834 0.050557 0.305425
Oberösterreich 0.158238 0.204371 0.254380 1.000000 0.302158 0.281724 0.087873 0.058567 0.136568
Salzburg 0.215667 0.174961 0.056712 0.302158 1.000000 0.147841 0.048454 0.099006 -0.002572
Steiermark 0.053402 -0.078889 0.266859 0.281724 0.147841 1.000000 0.114753 0.120173 -0.137818
Tirol 0.075323 0.158289 0.144834 0.087873 0.048454 0.114753 1.000000 0.163309 0.149731
Vorarlberg -0.002346 0.029424 0.050557 0.058567 0.099006 0.120173 0.163309 1.000000 0.003840
Wien 0.153621 0.305569 0.305425 0.136568 -0.002572 -0.137818 0.149731 0.003840 1.000000